"""
字段信息表模型 - 对应现有的field_schema表
"""
from sqlalchemy import Column, Integer, String, Text, DateTime, Boolean, BigInteger
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.sql import func

Base = declarative_base()

class FieldSchema(Base):
    """字段信息表-专注数据生成"""
    __tablename__ = "field_schema"
    
    id = Column(BigInteger, primary_key=True, autoincrement=True, comment="主键ID")
    object_api_name = Column(String(100), nullable=False, comment="对象API名称")
    field_api_name = Column(String(100), nullable=False, comment="字段API名称")
    field_label_zh = Column(String(200), comment="字段中文标签")
    field_label_en = Column(String(200), comment="字段英文标签")
    field_type = Column(String(50), nullable=False, comment="字段类型")
    is_required = Column(Boolean, default=False, comment="是否必填 0-否 1-是")
    is_unique = Column(Boolean, default=False, comment="是否唯一 0-否 1-是")
    is_multiple = Column(Boolean, default=False, comment="是否多值 0-否 1-是")
    generation_rules = Column(Text, comment="数据生成规则(JSON格式)，包含所有生成测试数据需要的约束和配置")
    created_at = Column(DateTime, default=func.current_timestamp(), comment="创建时间")
    updated_at = Column(DateTime, default=func.current_timestamp(), onupdate=func.current_timestamp(), comment="更新时间")
    
    def __repr__(self):
        return f"<FieldSchema(object_api_name='{self.object_api_name}', field_api_name='{self.field_api_name}', field_type='{self.field_type}')>" 